package com.sntk.organauthomanager.domain.model;

import com.sntk.organauthomanager.infrastructure.exception.DataEmptyException;
import lombok.Getter;

/**
 * @ClassName: AffiliateInfo
 * @author: wgchao
 * @createTime: 2020/9/16 8:56 AM
 * @Description: 关联机构信息
 */
@Getter
public class AffiliateInfo extends ValueObject {

    //机构编号
    private String institutionNumber;

    //HIS用户编号
    private String hisCode;

    public AffiliateInfo(Organization organization, String hisCode) {
        if(organization == null){
            throw new DataEmptyException("机构信息缺失");
        }
        this.institutionNumber = organization.getInstitutionNumber();
        this.hisCode = hisCode;
    }

    @Override
    public int hashCode() {
        int result = 17;
        result = 31 * result + (institutionNumber == null ? 0 : institutionNumber.hashCode());
        return result;
    }

    @Override
    public boolean equals(Object obj) {
        if(this == obj){
            return true;//地址相等
        }

        if(obj == null){
            return false;//非空性：对于任意非空引用x，x.equals(null)应该返回false。
        }

        if(obj instanceof AffiliateInfo){
            AffiliateInfo other = (AffiliateInfo) obj;
            //需要比较的字段相等，则这两个对象相等
            if(this.institutionNumber.equals(other.institutionNumber)){
                return true;
            }
        }

        return false;
    }
}
